﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;

namespace Demo;

public class Program
{
    public static async Task<int> Main(string[] args)
    {
        Log.Logger = new LoggerConfiguration()
#if DEBUG
            .MinimumLevel.Debug()
#else
            .MinimumLevel.Information()
#endif
            .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
            .Enrich.FromLogContext()
            .WriteTo.Async(c => c.File("Logs/logs.txt"))
            .WriteTo.Async(c => c.Console())
            .CreateLogger();

        try
        {
            await Host.CreateDefaultBuilder(args)
                .ConfigureServices(services =>
                {
                    services.AddHostedService<AbpNanoHostedService>();
                })
                .UseSerilog()
                //.UseWindowsService()    //windows
                //.UseSystemd()       //linux
                .RunConsoleAsync();

            return 0;
        }
        catch (Exception ex)
        {
            throw ex;
            //Log.Fatal(ex, "Host terminated unexpectedly!");
            //return 1;
        }
        finally
        {
            Log.CloseAndFlush();
        }
    }
}

